package exception;

/*
    java异常处理机制：try...catch
    try{
        代码片段
    }catch(XXXException){
        当try的代码片段出现XXXException时的补救措施
    }
 */
public class TryCatchDemo {
    public static void main(String[] args) {
        System.out.println("程序开始了。。。");
        try {
            String line1=null;
            System.out.println(line1.length());
            String line2="";
            System.out.println(line2.charAt(0));
            String line3="abc";
            System.out.println(Integer.parseInt(line3));
        }catch (NullPointerException e){   //
            System.out.println("空指针异常");
        }catch (StringIndexOutOfBoundsException e){
            System.out.println("下标越界异常");
        }
        System.out.println("程序结束了。。。");
    }
}
